var imgFile,imgFile2;
$(function () {
    getUserList();
});
/*重置*/
function resetClick(){
    $(".dis-inebl input").val("");
    $("#type option:selected").text("全部");
    getUserList();
}
/*查询*/
function getUserList(init){
    JY.Model.loading();
	$("#ticktTable tbody").html("");
    var pageNum=$("#baseForm .pageNum").val();
    var pageSize=$("#baseForm .pageSize").val();
    var order=$("#order").val().trim();
    var type=$("#type option:selected").val();
    if($("#type option:selected").text()=="全部"){
        type="";
    }
    ym.ajax({
		url : "/shop/order/conditionalQuery",
		type : "post",
        param:{
            "pageNum":pageNum,
            "pageSize":pageSize,
            "shopOrderStatus":type,
            "shopOrderFlowno":order,
		},
		jsonType : "jsonp",
		success : function(data) {
            var data=data instanceof Object ? data : JSON.parse(data);
            console.log(data)
            var html="";
            var list=data.obj;
            var results=list.list;
            var pageNum=list.pageNum,
                pageSize=list.pageSize,
                totalRecord=list.totalRecord;
           if(results!=null&&results.length>0){
                var leng=(pageNum-1)*pageSize;//计算序号
                for(var i = 0;i<results.length;i++){
                    var l=results[i];
                    var jsonL=JSON.stringify(l);
                    html+="<tr class='tr_color'>";
                    html+="<td class='center ver-m'><label><input type='checkbox' name='ids' value='"+jsonL+"' class='ace' /> <span class='lbl'></span></label></td>";
                    html+="<td class='center'>"+l.shopOrderFlowno+"</td>";
                    if(l.shopOrderTotalcost==""||l.shopOrderTotalcost==null){
                        l.shopOrderTotalcost=0;
                    }
                    var shopOrderTotalcost=(l.shopOrderTotalcost*0.01).toFixed(2);
                    html+="<td class='center'>"+shopOrderTotalcost+"</td>";
                    if(l.shopOrderPoint==null||l.shopOrderPoint==""){
                        l.shopOrderPoint=0;
                    }
                    html+="<td class='center'>"+l.shopOrderPoint+"积分</td>";
                    html+="<td class='center'>"+l.shopOrderUserName+"</td>";
                    html+="<td class='center'>"+l.shopOrderUserMobile+"</td>";
                    html+="<td class='center'>"+l.userReceivingAddress+"</td>";
                    if(l.shopOrderStatus=="pendingPayment"){
                        html+="<td class='center'>待付款</td>";
                    }else if(l.shopOrderStatus=="pendingDelivery"){
                        html+="<td class='center'>待发货</td>";
                    }else if(l.shopOrderStatus=="pendingGoods"){
                        html+="<td class='center'>待收货</td>";
                    }else if(l.shopOrderStatus=="pendingEvaluated"){
                        html+="<td class='center'>待评价</td>";
                    }else if(l.shopOrderStatus=="theEnd"){
                        html+="<td class='center'>完成</td>";
                    }else if(l.shopOrderStatus=="fail"){
                        html+="<td class='center'>失败</td>";
                    }
                    html+="</tr>";
                }
                $("#ticktTable tbody").append(html);
                JY.Page.setPage("baseForm","pageing",pageSize,pageNum,totalRecord,"getUserList");
            }else{
                html+="<tr><td colspan='7' class='center'>没有相关数据</td></tr>";
                $("#ticktTable tbody").append(html);
                $("#baseForm ul").empty();//清空分页
            }
            JY.Model.loadingClose();
		}
	})
}
//查看
function checkClick(){
    clearData();
    var chks =[];
    $('#ticktTable input[name="ids"]:checked').each(function(){
        chks.push($(this).val());
    });
    if(chks.length==0) {
        JY.Model.info("您没有选择任何内容!");
    }else if(chks.length==1){
        var obj=JSON.parse(chks);
        console.log(obj);
        $("#generateForm input[name='shopOrderFlowno']").val(obj.shopOrderFlowno);
        if(obj.shopOrderPayMethod=="point"){
            $("#generateForm input[name='shopOrderPayMethod']").val("积分购买");
        }else{
            $("#generateForm input[name='shopOrderPayMethod']").val("混合购买");
        }
        if(obj.shopOrderProductcost==null||obj.shopOrderProductcost==""){
            obj.shopOrderProductcost=0;
        }
        var shopOrderTotalcosts=(obj.shopOrderProductcost*0.01).toFixed(2);
        $("#generateForm input[name='shopOrderProductcost']").val(shopOrderTotalcosts);//商品总价
        if(obj.shopOrderTotalcost==null||obj.shopOrderTotalcost==""){
            obj.shopOrderTotalcost=0;
        }
        var shopOrderTotalcost=(obj.shopOrderTotalcost*0.01).toFixed(2);
        $("#generateForm input[name='shopOrderTotalcost']").val(shopOrderTotalcost);//订单总价
        if(obj.shopOrderPoint==null||obj.shopOrderPoint==""){
            obj.shopOrderPoint=0;
        }
        $("#generateForm input[name='shopOrderPoint']").val(obj.shopOrderPoint+"积分");//积分
        var shopOrderTansportationcost=(obj.shopOrderTansportationcost*0.01).toFixed(2);
        $("#generateForm input[name='shopOrderTansportationcost']").val(shopOrderTansportationcost);
        $("#generateForm input[name='shopOrderPayTime']").val(obj.showPayTime);
        if(obj.shopOrderUserName==""||obj.shopOrderUserName==null||obj.shopOrderUserName==undefined){
            obj.shopOrderUserName="暂无"
        }
        $("#generateForm input[name='shopOrderUserName']").val(obj.shopOrderUserName);
        if(obj.shopOrderUserMobile==""||obj.shopOrderUserMobile==null||obj.shopOrderUserMobile==undefined){
            obj.shopOrderUserMobile="暂无"
        }
        $("#generateForm input[name='shopOrderUserMobile']").val(obj.shopOrderUserMobile);
        if(obj.userReceivingAddress==""||obj.userReceivingAddress==null||obj.userReceivingAddress==undefined){
            obj.userReceivingAddress="暂无"
        }
        $("#generateForm input[name='userReceivingAddress']").val(obj.userReceivingAddress);
        $("#shopOrderStatus").find("option[value = '"+obj.shopOrderStatus+"']").prop("selected","selected");
        JY.Model.check("auForm_edit","查看详情",function(){

        });
    }else if(chks.length>1){
        JY.Model.info("一次只能编辑一条信息!");
    }
}
function clearData(){
    $("#generateForm input").val("");
    $("#shopOrderStatus").find("option[value = 'pendingPayment']").prop("selected","selected");
    imgFile={};
    imgFile2={};
}
//导入
function inExcelClick(){
    JY.Model.edit("auForm_edits", "上传表格",function(){
        if(JY.Validate.form("oilTableTickets")){
            var that = $(this);
            var options = {
                type: 'post',//提交方式
                //url:"http://172.16.0.14:8083/shop/order/uploadExcel",//服务器
                url:"http://111.230.17.122:8083/shop/order/uploadExcel",
                success: function(data) {
                    that.dialog("close");
                    if(data.res==1){
                        getUserList();
                    }else{
                        JY.Model.info(data.message);
                    }
                }
            };
            $("#oilTableTickets").ajaxSubmit(options); // jquery 表单提交
            return false;  // 必须返回false，否则表单会自己再做一次提交操作，并且页面跳转
        }
    })
}
//导出
function outExcel(){
    var type=$("#typeOrder").find("option:selected").val();
    if(type!=""&&type!=null&&type!=undefined){
        ym.ajax({
            url : "/shop/order/countOrder",
            type : "post",
            param:{
                "orderStatus":type,
            },
            jsonType : "jsonp",
            success : function(data) {
                if(data.res==1){
                    //window.location.href="http://172.16.0.14:8083/shop/order/outExcel?orderStatus="+type;//服务器
                    window.location.href="http://111.230.17.122:8083/shop/order/outExcel?orderStatus="+type;
                }else{
                    JY.Model.info("暂无所选类型订单!");
                }
            }
        })

    }
}
